package com.anpy.common.service.model.vo;

/**
 * ResponseMessage工具类
 **/
public class Result {

    // 接口调用成功响应码：200
    public static final String RESPONSE_MESSAGE_CODE_SUCCESS = "200";
    // 接口调用失败响应码：500
    public static final String RESPONSE_MESSAGE_CODE_ERROR = "500";
    // 接口调用成功响应消息提示
    public static final String RESPONSE_MESSAGE_SUCCESS = "接口调用成功";
    // 接口调用失败响应消息提示
    public static final String RESPONSE_MESSAGE_ERROR = "接口调用失败";

    public static <T> ResponseMessage<T> success() {
        return success(Result.RESPONSE_MESSAGE_CODE_SUCCESS, Result.RESPONSE_MESSAGE_SUCCESS);
    }

    public static <T> ResponseMessage<T> success(String code, T t) {
        return success(code, Result.RESPONSE_MESSAGE_SUCCESS, t);
    }

    public static <T> ResponseMessage<T> success(String message) {
        return success(Result.RESPONSE_MESSAGE_CODE_SUCCESS, message, null);
    }

    public static <T> ResponseMessage<T> success(String code, String message) {
        return success(code, message, null);
    }

    public static <T> ResponseMessage<T> success(T t) {
        return success(Result.RESPONSE_MESSAGE_CODE_SUCCESS, Result.RESPONSE_MESSAGE_SUCCESS, t);
    }

    /**
     * 接口调用成功时生成响应对象，并指定响应码、消息提示信息和响应数据对象
     *
     * @param code    响应码
     * @param message 消息提示信息
     * @param t       响应数据
     * @param <T>     响应数据类型
     * @return ResponseMessage<T>
     */
    public static <T> ResponseMessage<T> success(String code, String message, T t) {
        return new ResponseMessage<>(code, message, t);
    }

    /**
     * 接口调用失败时生成响应对象，并指定响应码为500和响应数据对
     *
     * @return ResponseMessage
     */
    public static <T> ResponseMessage<T> error() {
        return error(Result.RESPONSE_MESSAGE_CODE_ERROR, Result.RESPONSE_MESSAGE_ERROR);
    }

    public static <T> ResponseMessage<T> error(String message) {
        return error(Result.RESPONSE_MESSAGE_CODE_ERROR, message);
    }

    public static <T> ResponseMessage<T> error(String code, String message) {
        return error(code, message, null);
    }

    public static <T> ResponseMessage<T> error(T t) {
        return error(Result.RESPONSE_MESSAGE_CODE_ERROR, Result.RESPONSE_MESSAGE_ERROR, t);
    }

    public static <T> ResponseMessage<T> error(String message, T t) {
        return error(Result.RESPONSE_MESSAGE_CODE_ERROR, message, t);
    }

    /**
     * 接口调用失败时生成响应对象，并指定响应码、消息提示信息和响应数据对象
     *
     * @param code    响应码
     * @param message 消息提示信息
     * @param t       响应数据
     * @param <T>     响应数据类型
     * @return ResponseMessage<T>
     */
    public static <T> ResponseMessage<T> error(String code, String message, T t) {
        return new ResponseMessage<>(code, message, t);
    }
}
